package cn.stylefeng.guns.sys.modular.tao.service.serviceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.tao.entity.RechargeRecord;
import cn.stylefeng.guns.sys.modular.tao.mapper.RechargeRecordMapper;
import cn.stylefeng.guns.sys.modular.tao.model.params.RechargeRecordParam;
import cn.stylefeng.guns.sys.modular.tao.model.result.RechargeRecordResult;
import  cn.stylefeng.guns.sys.modular.tao.service.RechargeRecordService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 微信会员充值发起记录表 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-08-14
 */
@Service
public class RechargeRecordServiceImpl extends ServiceImpl<RechargeRecordMapper, RechargeRecord> implements RechargeRecordService {
     @Autowired
     RechargeRecordMapper rechargeRecordMapper;
    @Override
    public void add(RechargeRecordParam param){
        RechargeRecord entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(RechargeRecordParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(RechargeRecordParam param){
        RechargeRecord oldEntity = getOldEntity(param);
        RechargeRecord newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public RechargeRecordResult findBySpec(RechargeRecordParam param){
        return null;
    }

    @Override
    public List<RechargeRecordResult> findListBySpec(RechargeRecordParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(RechargeRecordParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public RechargeRecordParam getRechargeRecordById(String orderNo) {
        return rechargeRecordMapper.getRechargeRecordById(orderNo);
    }

    private Serializable getKey(RechargeRecordParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private RechargeRecord getOldEntity(RechargeRecordParam param) {
        return this.getById(getKey(param));
    }

    private RechargeRecord getEntity(RechargeRecordParam param) {
        RechargeRecord entity = new RechargeRecord();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
